import { service } from '@/utils/request'
import { Song, Album, Artist } from '.'

export type ResEntities = Song | Album | Artist

export const defaultSearchResult: SearchResponse<ResEntities> = {
  data: [],
  count: 0,
  total: 0,
  page: 0,
  pageCount: 0,
  type: ''
}

export interface SearchResponse<T> {
  data: T[];
  count: number;
  total: number;
  page: number;
  pageCount: number;
  type: string;
}

/**
 * 曲库搜索
 * @param s 搜索词
 * @param i 类别
 * @param page 页号
 */
export function search (s: string, i: string, page?: number) {
  return service.get<SearchResponse<ResEntities>>(
    '/resources/search',
    {
      params: { s, i, page }
    }
  )
}
